import os

root = os.path.dirname(os.path.abspath(__file__))

# 定义需要创建主类的模块
modules = [
    ("scene-server", "com.gzc.just.play.last.war.sceneserver", "SceneServerApplication"),
    ("central-server", "com.gzc.just.play.last.war.centralserver", "CentralServerApplication"),
    ("balance-server", "com.gzc.just.play.last.war.balanceserver", "BalanceServerApplication"),
    ("login-server", "com.gzc.just.play.last.war.loginserver", "LoginServerApplication"),
]

template = """package {package};

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * {class_name}
 * {desc}
 */
@SpringBootApplication
public class {class_name} {{
    private static final Logger log = LoggerFactory.getLogger({class_name}.class);
    
    public static void main(String[] args) {{
        log.info("Starting {desc}...");
        SpringApplication.run({class_name}.class, args);
        log.info("{desc} started successfully");
    }}
}}
"""

for module, package, class_name in modules:
    # 创建目录
    package_path = package.replace(".", "/")
    dir_path = os.path.join(root, module, "src", "main", "java", package_path)
    os.makedirs(dir_path, exist_ok=True)
    
    # 创建文件
    file_path = os.path.join(dir_path, f"{class_name}.java")
    desc = class_name.replace("Application", " Application")
    
    with open(file_path, 'w', encoding='utf-8') as f:
        f.write(template.format(package=package, class_name=class_name, desc=desc))
    
    print(f"✅ 已创建: {file_path}")

print("\n✅ 所有主类创建完成")
